package com.sc.smartcommunity.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sc.smartcommunity.domain.PaymentRecord;
import com.sc.smartcommunity.mapper.PaymentRecordMapper;
import com.sc.smartcommunity.service.PaymentRecordService;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

/**
 * @author Chenke Zhao
 * @date 2025/9/10 20:53
 * @description paymentRecordServiceImpl
 */
@Service
public class PaymentRecordServiceImpl extends ServiceImpl<PaymentRecordMapper, PaymentRecord> implements PaymentRecordService {

    @Override
    public List<PaymentRecord> getPaymentRecords(String loginId) {
        return this.list(new LambdaQueryWrapper<PaymentRecord>()
                .eq(PaymentRecord::getPhone, loginId));
    }

    @Override
    public void addPaymentRecord(PaymentRecord paymentRecord) {
        this.save(paymentRecord);
    }

    @Override
    public BigDecimal getTotalSuccessPaymentAmount() {
        // 只统计交易成功的记录(status=1)
        return baseMapper.selectTotalAmountByStatus(1);
    }

}
